CC = gcc
#get all .c files in current directory 
src=$(wildcard ./*.c)
#matches the corresponding files in the current directory
obj=$(patsubst ./%.c,./%.o,$(src))
#link to library

USELIB = USE_WIRINGPI_LIB
# USELIB = USE_DEV_LIB
DEBUG = -D $(USELIB)
ifeq ($(USELIB), USE_WIRINGPI_LIB)
    DLIBS = -lwiringPi -lm
else ifeq ($(USELIB), USE_DEV_LIB)
    DLIBS = -llgpio -lm
endif
#name of the excutable file
app=main
CFLAGS += $(DEBUG)
$(app):$(obj)
	$(CC) $(CFLAGS) $(obj) -o $(app) $(DLIBS)

#output all .o files
$(obj):./%.o:./%.c 	
	$(CC) $(CFLAGS) -c $< -o $@ $(DLIBS)

.PHONY:clean all
clean:
	-rm *.o $(app)
$(info clean successful)

#this file should be located in current root directory
#the name of excutable file can modify in "app = main" 
#make clean command is clear all output files 
#if has other library then should be added in DLIBS
